package ap1112.ga1.rocco;


public class AP1112HS4 {

  static int[][] bays = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }};
    static int[] cont = {24, 22, 19, 18, 15, 13, 11, 10, 9, 7, 6, 5};


    /**
     * @param args
     */
    public static void main(String[] args) {
        int usedBay = 0;

        System.out.println("Ebene 1: " + bays.length);
        System.out.println("Ebene 2: " + bays[0].length);
       
        for (int i =0;i<cont.length;i++) {
            usedBay = bayRoutine();
            bayadd(usedBay, cont[i]);
        }
        showing();
    }

    private static int bayRoutine() {
        int counter = 0, bay = 0, minWeight = 9999;
        for (int j= 0;j< bays.length;j++) {
            int bayWeight = 0;
            for (int k = 0;k< bays[j].length;k++) {
                bayWeight = bayWeight + bays[j][k];

            }
            if (empty(bays[j]) && bayWeight < minWeight ) {

                minWeight = bayWeight;
                bay = counter;
            }
            counter++;
        }
        return bay;
    }

    private static void bayadd(int usedBay, int cont) {
       
        for (int i = 0; i < bays[0].length; i++) {

       
            if (bays[usedBay][i] == 0){
           
                bays[usedBay][i] = cont;
                break;

            }
        }

    }

    static boolean empty(int[] array) {
        for (int i = array.length-1; i > 0; i--) {
            if (array[i] == 0) {
                return true;
            }
        }
        return false;
    }

    static void showing(){

        System.out.println("Showing");
        for (int i = 0; i < bays.length; i++) {
            System.out.print("|");

            for (int j = 0; j < bays[0].length; j++) {
                System.out.print(bays[i][j] + "|");
            }
            System.out.println();
        }

    }

}
